package com.hnkywl.sts.service.report;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hnkywl.sts.dao.report.CwkcDao;
import com.hnkywl.sts.dao.report.FkhzjbDao;
import com.hnkywl.sts.entity.organ.Ejzh;
import com.hnkywl.sts.entity.sfgl.Sfk;
import com.hnkywl.sts.util.BaseUtils;
import net.ruixin.orm.hibernate.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-6-15
 * Time: 下午9:23
 * To change this template use File | Settings | File Templates.
 */
@Service
public class FkhzjbService {
   private FkhzjbDao fkhzjbDao;

    @Transactional
    public String findfkhzjbList(String gsMc,String khMc, int pageNo, int pageSize) {
        Page<Map> page = fkhzjbDao.findfkhzjbList(gsMc, khMc, pageNo, pageSize);
        Gson gson = new Gson();
        String json = gson.toJson(page.getResult());
        return "{\"total\":" + page.getTotalCount() + ",\"rows\":" + json + "}";
    }

    /**
     * 根据khid查询付款审核列表
     * @param khId
     * @param kxsy
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Transactional
    public String findAllSkshByKhId(Long khId, Long kxsy, int pageNo, int pageSize) {
        Page<Sfk> sfkPage = this.fkhzjbDao.findSklxListByKhId(khId,kxsy, pageNo, pageSize);
        List<Sfk> ygList = sfkPage.getResult() == null ? new ArrayList<Sfk>() : sfkPage.getResult();
        Double sfzje = 0d;
        if (ygList.size() > 0) {
            for (Sfk s : ygList) {
                sfzje += s.getSfje();
            }
        }
        String ygJson = BaseUtils.fetchCollectionToJson(ygList, "id", "bm", "sfkrq", "sfklx", "gldw.qc", "kxyt.z", "kxsy.z", "fkfs.z", "sfje", "pjlx.z", "kxlx", "sbgs.jc", "sbr.xm", "bz", "zt", "shrq", "khfksj", "pjhm", "ye", "fplx", "sfhz");
        return "{\"total\":" + sfkPage.getTotalCount() + ",\"rows\":[" + ygJson + "]}";
    }

    @Autowired
    public void setFkhzjbDao(FkhzjbDao fkhzjbDao) {
        this.fkhzjbDao = fkhzjbDao;
    }
}
